﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;
using System.Configuration;
using System.Security.Cryptography;

using ProgramMain.Framework;

namespace ProgramMain
{
    public partial class FrmLogin : DevExpress.XtraEditors.XtraForm
    {
        public FrmLogin()
        {
            InitializeComponent();
            this.Icon = GlobalData.DefaultIcon();
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {
            this.txtLogin.Text = BaseSecurity.SettingsUserName;
            try
            {
                string strPassword = BaseSecurity.SettingsUserPassword;
                if (strPassword.Length > 0)
                {
                    this.txtPassword.Text = strPassword;
                    this.checkSavePassword.Checked = this.txtPassword.Text.Length > 0;
                }
                if (this.checkSavePassword.Checked)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                //do nothing
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }

        private void FrmLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK)
            {
                e.Cancel = !BaseSecurity.LoadUserRights(txtLogin.Text, txtPassword.Text, checkSavePassword.Checked);
            }
            else
            {
                e.Cancel = false;
            }
        }
    }
}